#include "Part.hpp"

Part::Part() : _data(NULL), _nbParts(0)
{
  // infos concernant l'id obj
  Element       id;
  id.size = ID_SIZE;
  id.start = 0;
  _elmStruct.push_back(id);
  // infos concernant l'affichage (visible ou non)
  Element	vs;
  vs.size = VS_SIZE;
  vs.start = id.size;
  _elmStruct.push_back(vs);
  // infos concernant le refresh (à updater ou non)
  Element	nr;
  nr.size = NR_SIZE;
  nr.start = vs.start + vs.size;
  _elmStruct.push_back(nr);

  _partSize = 0;
  for(int i = 0; i < _elmStruct.size(); ++i)
      _partSize += _elmStruct[i].size;
}

void		Part::setDim(size_t dim)
{
  if (_nbParts < dim || _nbParts > 2*dim)
    {
      size_t	required_bytes = ((dim * _partSize) / 8) + 1;

      if ((_data = realloc(_data, required_bytes)) != NULL)
	{
	  std::cout << "Allocated " << required_bytes << " bytes for "
		    << dim << " elements from one with " << _nbParts << ".\n";
	  _nbParts = dim;
	}
      else
	{
	  std::cout << "Failed Allocation !!!\n";
	  _nbParts = 0;
	}
    }
}

void		Part::getSize() const
{
  return _nbParts;
}

void		Part::set(size_t num, void* Element)
{
  
}

void*		Part::get(size_t num, ElementRef part) const
{
  
}

void*           Part::set(size_t num, size_t part, void* data) const
{

}

void*		Part::get(size_t num) const
{
  size_t	bStart = num * _partSize;
}

